package com.itheimaoa.service.process.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheimaoa.domain.QueryResult;
import com.itheimaoa.domain.process.Resume;
import com.itheimaoa.service.base.impl.CommonServiceImpl;
import com.itheimaoa.service.process.IResumeService;

@Service
@Transactional
public class ResumeServiceImpl extends CommonServiceImpl<Resume> implements IResumeService {

	@Override
	public void saveEntity(Resume t) {
		// TODO Auto-generated method stub
		super.saveEntity(t);
	}

	@Override
	public void deleteEntity(Serializable id) {
		// TODO Auto-generated method stub
		super.deleteEntity(id);
	}

	@Override
	public void updateEntity(Resume t) {
		// TODO Auto-generated method stub
		super.updateEntity(t);
	}

	@Override
	public Resume findEntity(Serializable id) {
		// TODO Auto-generated method stub
		return super.findEntity(id);
	}

	@Override
	public Collection<Resume> getEntitys() {
		// TODO Auto-generated method stub
		return super.getEntitys();
	}

	@Override
	public QueryResult<Resume> getQueryResult(Integer firstResult, Integer maxResult, String strWhere, Object[] params, LinkedHashMap<String, String> orderby) {
		// TODO Auto-generated method stub
		return super.getQueryResult(firstResult, maxResult, strWhere, params, orderby);
	}

	@Override
	@Transactional(readOnly = true)
	public Resume findApplyId(String applyId) {
		String jpql = " from Resume o where o.apply.aid = ? order by o.uptime desc";
		List<Resume> resumes = this.hibernateTemplate.find(jpql, applyId);
		if (resumes != null && resumes.size() > 0) {
			return resumes.get(0);
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public Resume findResumeByApplyId(String applyId) {
		String jpql = " from Resume o where o.apply.aid = ?";
		List<Resume> resumes = this.hibernateTemplate.find(jpql, applyId);
		if (resumes != null && resumes.size() > 0) {
			for (Resume r : resumes) {
				if (!r.getAgree()) {
					return r;
				}
			}
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public List<Resume> findResumesByApplyId(String applyId) {
		String jpql = " from Resume o where o.apply.aid = ? order by o.uptime asc";
		List<Resume> resumes = this.hibernateTemplate.find(jpql, applyId);
		return resumes;
	}

}
